﻿using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gadgeteer.Interfaces.Fakes.Tests
{
    [TestFixture]
    public class FakeClockTest
    {
        [SetUp]
        public void SetUp()
        {
            ServiceLocator.Locator.Setup();
        }

        [Test]
        public void ClockReturnsCurrentByDefault()
        {
            var clock = ServiceLocator.Locator.Clock;
            var fakeClock = clock as FakeClock;
            Assert.That(fakeClock, Is.Not.Null);

            Assert.That(clock.Current, Is.EqualTo(DateTime.Now));
        }

        [Test]
        public void ClockIsSettable_DateTime()
        {
            var clock = ServiceLocator.Locator.Clock;
            var fakeClock = clock as FakeClock;
            Assert.That(fakeClock, Is.Not.Null);

            var dateTime = new DateTime(2008, 6, 4, 12, 30, 0);
            fakeClock.Current = dateTime;

            Assert.That(clock.Current, Is.EqualTo(dateTime));
        }

        [Test]
        public void ClockIsSettable_DateFallsBackToDateTime()
        {
            var clock = ServiceLocator.Locator.Clock;
            var fakeClock = clock as FakeClock;
            Assert.That(fakeClock, Is.Not.Null);

            var dateTime = new DateTime(2008, 6, 4, 12, 30, 0);
            fakeClock.Current = dateTime;

            Assert.That(clock.Date, Is.EqualTo(dateTime.Date));
        }

        [Test]
        public void ClockIsSettable_DateCanBeDifferentDate()
        {
            var clock = ServiceLocator.Locator.Clock;
            var fakeClock = clock as FakeClock;
            Assert.That(fakeClock, Is.Not.Null);

            var dateTime = new DateTime(2008, 6, 4, 12, 30, 0);
            var dateTime2 = dateTime.AddDays(10);
            fakeClock.Current = dateTime;
            fakeClock.Date = dateTime2;

            Assert.That(clock.Current, Is.EqualTo(dateTime));
            Assert.That(clock.Date, Is.EqualTo(dateTime2.Date));
        }
    }
}
